package com.piece.blog.service;

import com.piece.blog.model.ArticleInfo;
import com.piece.blog.repository.ArticleInfoRepository;
import com.piece.core.jpa.repository.BaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.PostConstruct;
import java.util.HashMap;
import java.util.Map;

@Service
@Transactional
public class ArticleInfoService extends BaseService<ArticleInfo, String> {

    @Autowired
    private ArticleInfoRepository articleInfoRepository;

    @PostConstruct
    public void initRepository() {
        setRepository(articleInfoRepository);
    }

    public ArticleInfo findByArticle(Long articleId) {
        Map<String, Object> condition = new HashMap<>();
        condition.put("articleId", articleId);
        return articleInfoRepository.findOneByCondition(condition);
    }
}
